<script setup lang="ts">
import './node-style.scss'
import {inject, ref} from "vue";
import {ModelApi, ModelVO} from "@/api/ai/model/model";
import {AiModelTypeEnum} from "@/views/ai/utils/constants";
import {Node} from "@antv/x6";

const formData = reactive<any>({
  modelId:undefined,
  strategy:undefined,
})
const models = ref([] as ModelVO[])
const init = async () => {
  models.value = await ModelApi.getModelSimpleList(AiModelTypeEnum.CHAT)
}
const id=ref<string>()
const getNode=inject<()=>Node>('getNode')
if(getNode){
  const node=getNode()
  id.value=node.id
  node.setData(formData)
}
onBeforeMount(()=>{
  if(getNode){
    const node=getNode()
    const d=node.getData()
    if (d){
      Object.assign(formData,d)
    }else {
      node.setData(formData)
    }
  }
})
onMounted(() => {
  init()
})
watch(formData,()=>{
  if(getNode){
    const node=getNode()
    node.setData(formData)
  }
},{deep:true,immediate:false})
</script>

<template>
  <div class="node">
    <div class="node-title line5">
      <div class="flow-dot" magnet="true" :class="'flow-exec'" x-type="input-exec" :x-id="'input-exec_'+id"></div>
      <div>多模态转换</div>
      <div class="flow-dot flow-right flow-exec" magnet="true" x-type="output-exec" :x-id="'output-exec_'+id"></div>
    </div>
    <div class="line5">
      <div class="flow-dot flow-file" magnet="true" x-type="input-files" :x-id="'input-files_'+id"></div>
      <div>文件列表</div>
    </div>
    <div class="line5">
      <div class="flow-right">参考资料</div>
      <div class="flow-dot flow-array-string" magnet="true" x-type="output-array-string" :x-id="'output-array-string_'+id" x-key="strings"></div>
    </div>
    <el-form
      :model="formData"
      label-position="top"
      @mousedown.stop
      @focus.stop
      style="cursor: default"
    >
      <el-form-item label="解析策略">
        <el-select placeholder="请选择解析策略" v-model="formData.strategy">
          <el-option value="BY_AI" label="通过AI提取描述"/>
          <el-option value="BY_SYS" label="依据文件类型的默认策略"/>
        </el-select>
        <el-alert v-if="formData.strategy==='BY_SYS'" description="目前‘默认策略’仅支持文本文件"/>
      </el-form-item>
      <el-form-item v-if="formData.strategy==='BY_AI'" label="解析模型(必须用多模态)">
        <el-select v-model="formData.modelId">
          <el-option v-for="item in models" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </el-form-item>
    </el-form>
  </div>
</template>

<style scoped lang="scss">

</style>
